<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";

    String type = request.getParameter("type");
    String budgetId = request.getParameter("budgetId");
%>
<html>
<head>
    <title>新建项目</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <link type="text/css" rel="stylesheet" href="/lib/budget/styles.css"/>
    <link rel="stylesheet" href="/css/notice/noticeManagement.css">
    <link rel="stylesheet" href="/css/base/base.css?20201106.1">
    <link rel="stylesheet" type="text/css" href="/css/commonTheme/${sessionScope.InterfaceModel}/commonTheme.css"/>

    <script type="text/javascript" charset="utf-8" src="/lib/jQuery-File-Upload-master/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/lib/laydate/laydate.js"></script>
    <script type="text/javascript" charset="utf-8" src="/lib/layer/layer.js?20201106"></script>
    <script type="text/javascript" charset="utf-8" src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" ></script>
    <script type="text/javascript" charset="utf-8" src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" ></script>
    <script type="text/javascript" charset="utf-8" src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" ></script>
    <script type="text/javascript" charset="utf-8" src="/js/base/base.js"></script>
    <style>
        a{
            text-decoration: none;
        }
        .main{
            /*width: 788px;*/
            margin: 0 auto;
            box-sizing: border-box;
            /*box-shadow: 0px 0px 16px 5px #b8b3b3;*/
            padding: 14px;
        }
        .nav{
            font-weight: normal;
            display: inline-block;
            font-size: 22px;
            color: #494d59;
            vertical-align: middle;
            margin-left: 10px;
        }
        .leftspan{
            display: inline-block;
            width: 156px;
            text-align: right;
            margin-right: 52px;
        }
        ul,li{
            list-style: none;
            margin:12px 0;
            padding: 0;
        }
        input{
            width: 376px;
            height: 30px;
            border: 1px solid #ccc;
            border-radius: 2px;
            padding-left: 6px;
        }
        .inputsmall{
            width: 154px;
            height: 30px;
            text-align: center;
            padding-left: 0px;
        }
        .line{
           margin: 0 0px;
        }
        .btn{
            font-size: 14px;
            background-color: #008cff;
            padding: 4px 18px;
            border-radius: 3px;
            color: #fff;
            cursor:pointer;
        }
        textarea{
            width: 88%;
            height: 100px;
            padding-left: 6px;
        }
        .spspan{
            position: relative;
            bottom: 60px;
        }
        .list{
            text-align: center;
            margin: 60px 0;
        }
        .list span{
            font-size: 18px;
            background-color: #008cff;
            padding: 6px 48px;
            border-radius: 3px;
            color: #fff;
            cursor: pointer;
            margin: 0 3px;
        }
        .uploadbox{
            /*margin-left: 217px;*/
            padding-top: 6px;
        }
        select {
            width: 376px;
            height: 30px;
            border: 1px solid #ccc;
            border-radius: 2px;
            padding-left: 6px;
        }
        .mustinput{
            color: red;
            height: 26px;
            line-height: 32px;
            margin-left: 5px;
        }
        .red{
            color: red;
        }
        #save,.back{
            padding: 5px 15px;
            color: #fff;
            border-radius: 4px;
            background: #2F8AE3;
            margin: 0 10px;
            cursor:pointer;
        }
        .tableMain table tbody td input[type=text]{
            width:45%
        }
        .zhui{
            padding:4px 7px;
            color: #fff;
            border-radius: 4px;
            background: #2F8AE3;
            margin: 3px 10px 0px;
            display: inline-block;
            cursor: pointer;
        }



    </style>
</head>
<body>
<div class="main tableMain">
    <div style="margin-bottom:20px">
        <img src="/img/commonTheme/theme6/newsManages2_1.png" alt="">
        <span class="nav"></span>
    </div>

    <table style="width: 60%;margin:0 auto">
        <tbody>

        <tr>
            <td class="blue_text" width="22%">
                <p >项目排序号：<b class="red">*</b></p>
            </td>
            <td width="80%" style="text-align: left">
                <input type="text" id="budgetItemNo">
            </td>
        </tr>
        <tr>
            <td class="blue_text" width="22%">
                指标分类：
            </td>
            <td width="80%" style="text-align: left">
                <input type="text" id="quotaClassify">
            </td>
        </tr>
        <tr>
            <td class="blue_text" width="22%">
                项目名称：<b class="red">*</b>
            </td>
            <td width="80%" style="text-align: left">
                <input type="text" id="budgetItemName">
            </td>
        </tr>
        <tr>
            <td class="blue_text" width="22%">
                项目周期：<b class="red">*</b>
            </td>
            <td width="80%" style="text-align: left">
                   <span><input type="text" placeholder="请选择日期" style="text-align: left;width:20%" id="budgetItemBegindate" class="inputsmall" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"  ></span>
                    <span class="line">至</span>
                   <span><input type="text" placeholder="请选择日期" style="text-align: left;width:20%"  id="budgetItemEnddate" class="inputsmall" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"  ></span>
                </td>
            </tr>
            <tr>
                <td width="22%" class="blue_text">
                    录入时间：
                </td>
                <td width="80%" style="text-align: left">
                    <input type="text" placeholder="请选择日期" id="inputTime" style="padding-left: 10px" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"  >
            </td>
        </tr>

        <tr>
            <td class="blue_text" width="22%">
                上级项目：
            </td>
            <td width="80%" style="text-align: left">
                <select name="postPriv" class="BigSelect" id="priveItem">
                    <option value="0">请选择上级项目(不选为一级项目)</option>
                </select>
            </td>
        </tr>
        <tr>
            <td class="blue_text" width="22%">
                额度号：<b class="red">*</b>
            </td>
            <td width="80%" class="files" id="files_txt">
                 <span id="lineNum" style="display: none">
                    <span><input type="text" id="lineNo1" disabled style="width: 160px"></span>
                    <%--<span><input type="text" id="lineNo2"  style="width: 210px"></span>--%>
                </span>
                <span id="newLineNum"><input type="text"  id="lineNo3"></span>
            </td>
        </tr>
        <tr>
            <td class="blue_text" width="22%">
                项目金额：<b class="red">*</b>
            </td>
            <td width="80%" class="files" id="">
                <span><input type="text"  id="itemMoney"></span>
                <input type="hidden" id="zhuiMon">
                <span class="zhui" style="display:none">追加金额</span>
                <span id="jingao" style="color: #CC2222;font-size: 14px;display: none">只能输入数字</span>
            </td>
        </tr>
        <tr class="newmoney" style="display: none">
            <td class="blue_text" width="22%">
                可用金额：<b class="red">*</b>
            </td>
            <td width="80%" class="files" >
                <span><input type="text"  id="remainingAmount"></span>
                <span class="editMon" style="display:none"><a href="javascript:;">编辑</a></span>
                <span id="jingao" style="color: #CC2222;font-size: 14px;display: none">只能输入数字</span>
            </td>
        </tr>
        <%--<tr class="newmoney" style="display: none">--%>
            <%--<td class="blue_text" width="20%">--%>
                <%--可用金额：<b class="red">*</b>--%>
            <%--</td>--%>
            <%--<td width="80%" class="files" id="">--%>
                <%--<span><input type="text"  id="kyje"></span>--%>
                <%--<span id="jingao" style="color: #CC2222;font-size: 14px;display: none">只能输入数字</span>--%>
            <%--</td>--%>
        <%--</tr>--%>
        <tr class="newmoney" style="display: none">
            <td class="blue_text" width="22%">
                预支出金额：<b class="red">*</b>
            </td>
            <td width="80%" class="files" >
                <span><input type="text"  id="allAdvance"></span>
                <span id="jingao" style="color: #CC2222;font-size: 14px;display: none">只能输入数字</span>
            </td>
        </tr>
        <tr>
            <td class="blue_text" width="22%">
                项目负责人：<b class="red">*</b>
            </td>
            <td width="80%" style="text-align: left">
                <input disabled class="td_title1 release1" id="itemManager" type="text" username="">
                <a href="javascript:;" class=" ml8 userPrivAdd  add3" name="orgAdd">添加</a>
                <a href="javascript:;" class=" ml8 userPrivClear  clear3" name="orgClear" style="color: red;">清除</a>
            </td>
        </tr>
        <tr>
            <td class="blue_text" width="22%">
                所属部门：<b class="red">*</b>
            </td>
            <td width="80%" style="text-align: left">
                <span><input disabled type="text" id="department"></span>
                <span class=" adddept" style="color: #2b7fe0;cursor:pointer">添加</span>
                <span class=" clear" style="color: red;cursor:pointer">清除</span>
            </td>
        </tr>
        <tr>
            <td class="blue_text" width="22%">
                项目执行人：<b class="red">*</b>
            </td>
            <td width="80%" style="text-align: left">
                <textarea disabled class="td_title1 release1" id="itemExecuter" type="text" username="" style="width: 74%;height:100px"></textarea>
                <a href="javascript:;" class=" ml8 userPrivAdd  add4" name="orgAdd">添加</a>
                <a href="javascript:;" class=" ml8 userPrivClear  clear4" name="orgClear" style="color: red;">清除</a>
            </td>
        </tr>
        <tr>
            <td class="blue_text" width="22%">
                项目描述：
            </td>
            <td width="80%" style="text-align: left">
                <textarea name=""  id="itemDesc" style="background: #fff"></textarea>
            </td>
        </tr>
        <tr>
            <td class="blue_text" width="22%">
                附件文档：
            </td>
            <td width="80%" style="text-align: left">
                <div class="uploadbox"></div>
            </td>
        </tr>
        <tr>
            <td class="blue_text" width="22%">
                附件上传：
            </td>
            <td width="80%" style="text-align: left;position:relative">

                <span style="color:#2b7fe0;cursor:pointer;"><img src="/img/icon_uplod.png" style="margin-right:5px" alt="">附件上传</span>
                <form id="uploadimgform" style="display: inline-block;" target="uploadiframe"  action="/upload?module=budget"  class="xzbtn" enctype="multipart/form-data" method="post">
                <input type="file" multiple="multiple" name="file" id="uploadinputimg" class="w-icon5" style="cursor:pointer;position: absolute;top: 6px;opacity: 0;width: 93px;left: 24px;cursor:pointer;">
                </form>

            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center" class="btnarr">
                <span id="save">保存</span><span class="back">返回</span>
            </td>
        </tr>
        </tbody>
    </table>
    <%--<ul>--%>
        <%--<li>--%>
            <%--<span class="leftspan">项目排序号：<font class="mustinput">*</font></span>--%>

            <%--<span><input type="text" id="budgetItemNo"></span>--%>
        <%--</li>--%>
        <%--<li>--%>
            <%--<span class="leftspan">指标分类：<font class="mustinput">&nbsp;</font></span>--%>
            <%--<span><input type="text" id="quotaClassify"></span>--%>
        <%--</li>--%>
        <%--<li>--%>
            <%--<span class="leftspan">项目名称：<font class="mustinput">*</font></span>--%>

            <%--<span><input type="text" id="budgetItemName"></span>--%>

        <%--</li>--%>
        <%--<li>--%>
            <%--<span class="leftspan">项目周期：<font class="mustinput">*</font></span>--%>

            <%--<span><input type="text" placeholder="请选择日期" id="budgetItemBegintime" class="inputsmall" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"  ></span>--%>
            <%--<span class="line">至</span>--%>
            <%--<span><input type="text" placeholder="请选择日期" id="budgetItemEndtime" class="inputsmall" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"  ></span>--%>
        <%--</li>--%>
        <%--<li>--%>
            <%--<span class="leftspan">录入时间：<font class="mustinput">&nbsp;</font></span>--%>
            <%--<span><input type="text" id="inputTime"></span>--%>
            <%--<span><input type="text" placeholder="请选择日期" id="inputTime" style="padding-left: 10px" onclick="laydate({istime: true, format: 'YYYY-MM-DD'})"  ></span>--%>
        <%--</li>--%>
        <%--<li>--%>
            <%--<span class="leftspan">所属部门：<font class="mustinput">*</font></span>--%>

            <%--<span><input disabled type="text" id="department"></span>--%>
            <%--<span class="btn adddept">添加</span>--%>
            <%--<span class="btn clear">清除</span>--%>
        <%--</li>--%>
        <%--<li>--%>
            <%--<span class="leftspan">上级项目：<font class="mustinput">&nbsp;</font></span>--%>
            <%--<select name="postPriv" class="BigSelect" id="priveItem">--%>
                <%--<option value="0">请选择上级项目(不选为一级项目)</option>--%>
            <%--</select>--%>
        <%--</li>--%>
        <%--<li>--%>
            <%--<span class="leftspan">额度号：<font class="mustinput">*</font></span>--%>
            <%--<span id="lineNum" style="display: none">--%>
                <%--<span><input type="text" id="lineNo1" disabled style="width: 160px"></span>--%>
                <%--<span><input type="text" id="lineNo2"  style="width: 210px"></span>--%>
            <%--</span>--%>
            <%--<span id="newLineNum"><input type="text"  id="lineNo3"></span>--%>
        <%--</li>--%>

        <script>
            $(function () {
                // $('#priveItem').on('change',  function () {
                //     $('#newLineNum').css('display', 'none');
                //     $('#lineNum').css('display', 'inline-block');
                //     if($('#priveItem option:checked').html() == '请选择上级项目(不选为一级项目)'){
                //         $('#newLineNum').css('display', 'inline-block');
                //         $('#lineNum').css('display', 'none');
                //     }
                // })
            });
        </script>


        <%--<li>--%>
            <%--<span class="leftspan">项目金额：<font class="mustinput">*</font></span>--%>

            <%--<span><input type="text"  id="itemMoney"></span>--%>
            <%--<span id="jingao" style="color: #CC2222;font-size: 14px;display: none">只能输入数字</span>--%>
        <%--</li>--%>

        <%--<li>--%>
            <%--<span class="leftspan">项目负责人：<font class="mustinput">*</font></span>--%>


            <%--<input disabled class="td_title1 release1" id="itemManager" type="text" username="">--%>
            <%--<a href="javascript:;" class=" ml8 userPrivAdd btn add3" name="orgAdd">添加</a>--%>
            <%--<a href="javascript:;" class=" ml8 userPrivClear btn clear3" name="orgClear">清除</a>--%>
        <%--</li>--%>
        <%--<li>--%>
            <%--<span class="leftspan">项目执行人：<font class="mustinput">*</font></span>--%>

            <%--<input disabled class="td_title1 release1" id="itemExecuter" type="text" username="">--%>
            <%--<a href="javascript:;" class=" ml8 userPrivAdd btn add4" name="orgAdd">添加</a>--%>
            <%--<a href="javascript:;" class=" ml8 userPrivClear btn clear4" name="orgClear">清除</a>--%>
        <%--</li>--%>
        <%--<li>--%>
            <%--<span class="leftspan spspan">项目描述：<font class="mustinput">&nbsp;</font></span>--%>
            <%--<span><textarea name=""  id="itemDesc"></textarea></span>--%>
        <%--</li>--%>
        <%--<li style="position: relative">--%>
            <%--<span class="leftspan last">附件上传：</span>--%>
                <%--<span class="btn">添加文件</span>--%>
                <%--<form id="uploadimgform" style="display: inline-block;" target="uploadiframe"  action="/upload?module=budget"  class="xzbtn" enctype="multipart/form-data" method="post">--%>
                    <%--<input type="file" multiple="multiple" name="file" id="uploadinputimg" class="w-icon5" style="position: absolute;top: -4px;opacity: 0;width: 93px;left: 212px;cursor:pointer;">--%>
                <%--</form>--%>
            <%--<div class="uploadbox"></div>--%>
        <%--</li>--%>
        <%--<li class="list"><span id="save">保存</span><span class="back">返回</span></li>--%>
    <%--</ul>--%>
</div>
</body>
<script>
    $('#budgetItemBegindate').val(new Date().Format('yyyy-MM-dd'))
    $('#budgetItemEnddate').val(new Date().Format('yyyy-MM-dd'))
    $.ajax({
        url:'/budget/generateBudgetNo',
        dataType:'json',
        success:function(res){
            $('#budgetItemNo').val(res)
        }
    })

    $('#inputTime').val(new Date().Format('yyyy-MM-dd hh:mm:ss'))
    //文本框数字的判断
    $("#itemMoney").keyup(function(){
        var val = $(this).val();
        if(isNaN(val)){
            $(this).val('')
            $('#jingao').css('display','inline')
        }else {
            $('#jingao').css('display','none')
        }
    })


        $(function () {
            var aTagNumber = 1;
            var type = <%=type%>;
            var budgetId = <%=budgetId%>;
            $.ajax({
                type: 'get',
                url: '/budget/selAllBudget',
                dataType: 'json',
                success: function (res) {
                    var str = '';
                    if (res) {
                        $.each(res.obj, function (index, res) {
                            str += '<option value="' + res.budgetId + '">' + res.budgetItemName + '</option>'
                        });
                        $('select').append(str);
                    }
                }
            });

//        function initData() {
//            $.ajax({
//                type: "get",
//                url: "/budget/selAllBudget",
//                dataType: 'json',
//                success: function (res) {
//                    $("#priveItem option").each(function (){
//                        var value = $(this).val();
//                    if(value == budgetId){
//                        $(this).attr("selected", "selected");
//                    }
//                    });
//                }
//            });
//
//
//        }


            $('.adddept').click(function () {
                dept_id = 'department';
                $.popWindow("../../common/selectDept?0");
            })


            $('.add2').click(function () {
                layer.open({
                    type: 1,
                    title: ['请选择部门', 'background-color:#2b7fe0;color:#fff;'],
                    area: ['600px', '420px'],
                    btn: ['导入', '取消'],
                    content: '',
                    success: function () {

                    },
                    yes: function (obj) {


                    }
                })
            })


            $('.add3').click(function () {
                user_id = 'itemManager';
                /*$.popWindow("../../common/roleMapper");*/
                $.popWindow("../../common/selectUser");
            })
            $('.add4').click(function () {
                user_id = 'itemExecuter';
                $.popWindow("../../common/selectUser");
            })
            $('.clear').click(function () {
                $(this).siblings().find('input').removeAttr('deptname').removeAttr('deptno').removeAttr('deptid').val('')
            })
            // 清空人员信息
            $('.clear3').click(function () {
                $('#itemManager').attr("privid", "");
                $('#itemManager').attr("user_id", "");
                $('#itemManager').val("");
            });
            $('.clear4').click(function () {
                $('#itemExecuter').attr("privid", "");
                $('#itemExecuter').attr("user_id", "");
                $('#itemExecuter').val("");
            });


            //删除附件
            $('.uploadbox').on('click', '.deImgs2', function () {
                var data = $(this).parents('.dech').attr('attachmentUrl');
                var dome = $(this).parents('.dech');
                deleteChatment(data, dome);
            })

            // //编辑中删除附件
                $('.uploadbox').on('click','.deImgs',function(){
                var data=$(this).parents('.dech').attr('attachmentUrl');
                var dome=$(this).parents('.dech');
                deleteChatment(data,dome);
            })

            function deleteChatment2(element) {
                layer.confirm('<fmt:message code="workflow.th.que" />？', {
                    btn: ['<fmt:message code="global.lang.ok" />', '<fmt:message code="depatement.th.quxiao" />'], //按钮
                    title: "<fmt:message code="notice.th.DeleteAttachment" />"
                }, function () {

                    //确定删除，调接口
                    $.ajax({
                        type: 'get',
                        url: '/budget/delAttachById1',
                        dataType: 'json',
                        data: {
                            budgetId: budgetId
                        },
                        success: function (res) {

                            if (res.flag == true) {
                                layer.msg('<fmt:message code="workflow.th.delsucess" />', {icon: 6});
//                                     var file = $('[name="file"]')
//                                     file.after(file.clone().val(""));
//                                     file.remove();
                                element.remove();
                            } else {
                                layer.msg('<fmt:message code="lang.th.deleSucess" />', {icon: 6});
                            }
                        }
                    });

                }, function () {
                    layer.closeAll();
                });
            }


            function deleteChatment(data, element) {
                layer.confirm('确定删除吗？', {
                    btn: ['确定','取消'], //按钮
                    title:"删除附件"
                }, function(){
                    //确定删除，调接口
                    //确定删除，调接口

                    $.ajax({
                        type: 'get',
                        url: '../delete',
                        dataType: 'json',
                        data: data,
                        success: function (res) {

                            if (res.flag == true) {
                                layer.msg('<fmt:message code="workflow.th.delsucess" />', {icon: 6});
//                                     var file = $('[name="file"]')
//                                     file.after(file.clone().val(""));
//                                     file.remove();
                                element.remove();
                            } else {
                                layer.msg('<fmt:message code="lang.th.deleSucess" />', {icon: 6});
                            }
                        },
                        error:function(){

                        }
                    });

                }, function(){
                    layer.closeAll();
                });

            }

            function inputcheck(name, value) {
                $('#' + name + '').val(value)
            }

            function preveCheck(name, value) {
                $('#' + name + '').text(value)
            }

            if (type == 1) {
                $('.nav').text('新建预算项目');
                $('.newmoney').hide();
                $('#save').click(function () {
                    if (mustWrite() == false) {
                        return;
                    }
                    var attachmentId = ""
                    var attachmentName = ""
                    if ($('.uploadbox .inHidden')) {
                        for (var i = 0; i < $('.uploadbox .inHidden').length; i++) {
//                        attachmentId+=$('.uploadbox .inHidden').eq(i).val()+','
                            attachmentId += $('.uploadbox .inHidden').eq(i).val();
                            attachmentName += $('.uploadbox ').find('.dech>a').eq(i * aTagNumber).attr('NAME')
                        }
                    }
                    if (attachmentId != '') {
                        var attachmentIdArr = attachmentId.split('?')[1];
                        var attachmentUrl = attachmentIdArr;
                    }

                    var budgetItemNo = $('#budgetItemNo').val();
                    var quotaClassify = $('#quotaClassify').val();
                    var budgetItemName = $('#budgetItemName').val();
                    var budgetItemBegindate = $('#budgetItemBegindate').val();
                    var budgetItemEnddate = $('#budgetItemEnddate').val();
                    var inputTime = $('#inputTime').val();
                    if ($('#department').val()) {
                        var department = $('#department').attr('deptid').replace(',', '')
                    } else {
                        var department = ""
                    }

                    var lineNo1 = $('#lineNo1').val();
                    var lineNum = $('#lineNo2').val()
                    if ($('#lineNo2').val() == '') {
                        lineNum = $('#lineNo3').val()
                    }
                    var lineNo2 = lineNum;
//                var lineNo2=$('#lineNo2').val();
                    var priveItem = $("#priveItem option:checked").text();

                    var itemMoney = $('#itemMoney').val();
                    var itemExecuter = $('#itemExecuter').attr('user_id');
                    var itemManager = $('#itemManager').attr('user_id');
                    var itemDesc = $('#itemDesc').val();
                    var attachmentName = attachmentName;
                    // if($('#lineNo1').val() == ''){
                    //     var lineNo=lineNo2.toString();
                    // }else{
                    //     var lineNo=lineNo1.toString()+ ',' +lineNo2.toString();
                    // }

                    $.ajax({
                        url: '/budget/addBudgetItem',
                        type: 'post',
                        data: {
                            'budgetItemNo': budgetItemNo,
                            'quotaClassify': quotaClassify,
                            'budgetItemName': budgetItemName,
                            'budgetItemBegindate': budgetItemBegindate,
                            'budgetItemEnddate': budgetItemEnddate,
                            'inputTime': inputTime,
                            'deptId': department,
                            'lineNo': $('#lineNo3').val(),
                            'itemMoney': itemMoney,
                            /*'itemRate':itemRate,*/
                            'itemManager': itemManager,
                            'itemExecuter': itemExecuter,
                            'itemDesc': itemDesc,
                            'attachmentName': attachmentName,
                            'attachmentId': attachmentId,
                            'priveItem': priveItem

                        },
                        dataType: 'json',
                        success: function (res) {
                            if (res.msg == "新建项目重复") {
                                layer.msg("新建项目重复", {
                                    icon: 2,
                                    time: 1500 //2秒关闭（如果不配置，默认是3秒）
                                });
                            } else {
                                if (res.flag) {
                                    layer.msg("新建成功", {
                                        icon: 1,
                                        time: 1500 //2秒关闭（如果不配置，默认是3秒）
                                    }, function () {
                                        location.href = "/budget/budgetItemManage"
                                    });
                                } else {
                                    layer.msg("新建失败", {
                                        icon: 1,
                                        time: 1500 //2秒关闭（如果不配置，默认是3秒）
                                    })
                                }

                            }
                        }

//                        if(res){
//                            layer.msg("新建成功",{
//                                icon: 1,
//                                time: 1500 //2秒关闭（如果不配置，默认是3秒）
//                            },function(){
//                                location.href="/budget/budgetItemManage"
//                            });
//                        }

//                    }
                    })
                })

            }
            if (type == 2) {

                $('.nav').text('编辑预算项目');
                $('.newmoney').show();
                $('.zhui').show();
                $('.editMon').show();
                $('#itemMoney').attr('disabled', 'disabled')
                $('#remainingAmount').attr('disabled', 'disabled')


                $.ajax({
                    url: '/budget/selBudgetItemById',
                    type: 'get',
                    data: {
                        'budgetId': budgetId
                    },
                    dataType: 'json',
                    success: function (res) {

                        $('#newLineNum').css('display', 'none');
                        $('#lineNum').css('display', 'inline-block');

                        $("head>title").text("编辑预算项目");
                        var obj = res.object;
                        if (res) {
                            inputcheck('budgetItemNo', obj.budgetItemNo);
                            inputcheck('quotaClassify', obj.quotaClassify);
                            inputcheck('budgetItemName', obj.budgetItemName);
                            inputcheck('budgetItemBegindate', obj.budgetItemBegindate);
                            inputcheck('budgetItemEnddate', obj.budgetItemEnddate);
                            inputcheck('inputTime', obj.inputTime);
                            inputcheck('department', obj.deptName);
                            $('#department').attr('deptId', obj.deptId + ',');
//                        inputcheck('lineNo1',obj.lineNo);
                            preveCheck('priveItem>option:selected', obj.priveItem);
                            inputcheck('itemMoney', obj.itemMoney);
                            inputcheck('remainingAmount', obj.remainingAmount)
                            inputcheck('itemitemRate', obj.itemRate);
                            inputcheck('itemManager', obj.itemManagerName);
                            inputcheck('itemExecuter', obj.itemExecuterName);
                            inputcheck('allAdvance', obj.allAdvance)
                            inputcheck('itemDesc', obj.itemDesc);
                            $('#itemManager').attr('user_id', obj.itemManager)
                            $('#itemExecuter').attr('user_id', obj.itemExecuter)
//                        inputcheck('lineNo3', obj.lineNo);
                            /*设置额度号*/


                            var lineNos = obj.lineNo.split(',');
                            $('#lineNo2').hide();
                            $('#lineNo1').removeAttr('disabled')
                            inputcheck('lineNo1', lineNos[0]);
                            // inputcheck('lineNo2', lineNos[1]);
                            // if(obj.priveItem == '无'){
                            //     $('#lineNo1').hide()
                            //     inputcheck('lineNo2', lineNos[0]);
                            //
                            //
                            // }
                            var str = '';
                            var urlObj = obj.attachmentUrl;
                            var nameObj = obj.attachmentName;
                            var arrList = obj.attachments;
                            if (arrList != "" && arrList != undefined) {
                                if (arrList.length > 0) {
                                    for (var i = 0; i < arrList.length; i++) {
                                        str += '<div class="dech" attachmentUrl="' + encodeURI(arrList[i].attUrl) + '" style="display:block;margin:6px 0;"><a class="ATTACH_a" NAME="' + arrList[i].attachName + '" href="<%=basePath %>download?' + encodeURI(arrList[i].attUrl) + '"><img src="/img/attachment_icon.png" style="margin-right:5px" alt="">' + arrList[i].attachName + '</a><img class="deImgs2" style="margin-left:5px;cursor: pointer;" src="../img/file/icon_deletecha_03.png"/><input type="hidden" attachmentName="' + arrList[i].attUrl + '"  class="inHidden" value="' + arrList[i].aid + '@' + arrList[i].ym + '_' + arrList[i].attachId + ',"></div>';

                                    }
                                    $('.uploadbox').html(str);
                                }
                            }

                            if (!(urlObj == undefined || nameObj == undefined)) { // || obj.attachmentName == 'undefined'
                                str += '<div class="dech" attachmentUrl="' + encodeURI(urlObj) + '" style="display:block;margin:6px 0;"><a class="ATTACH_a" NAME="' + obj.attachmentName + '" href="<%=basePath %>download?' + encodeURI(urlObj) + '"><img src="/img/attachment_icon.png" style="margin-right:5px" alt="">' + nameObj + '</a><img class="deImgs2" style="margin-left:5px;cursor: pointer;" src="../img/file/icon_deletecha_03.png"/><input type="hidden" attachmentName="' + nameObj + '*"  class="inHidden" value=""></div>';

                            }
                            $('.uploadbox').html(str);


                        }
                    }
                })

                $('.editMon').click(function () {
                    $.layerMsg({content: '谨慎使用'})
                    $('#remainingAmount').removeAttr('disabled')
                })
                $('.zhui').click(function () {
                    layer.open({
                        title: '消息',
                        content: '<div style="width:100%;height:100%;"><span>追加金额：</span><input type="text" class="money"></div>',
                        area: ['500px', '170px'],
                        btn: ['确定', '关闭'],
                        yes: function (index) {
                            $('#zhuiMon').val($('.money').val())
                            $('#itemMoney').val((Number($('#itemMoney').val()) + Number($('.money').val())).toFixed(2))
                            $('#remainingAmount').val((Number($('#remainingAmount').val()) + Number($('.money').val())).toFixed(2))
                            layer.closeAll();
                        }, success: function () {

                        }
                    })
                })

                $('#save').click(function () {
                    if (mustWrite() == false) {
                        return;
                    }
                    var lineNo1 = $('#lineNo1').val();
                    var lineNum = $('#lineNo2').val()

                    var attachmentId = ""
                    var attachmentName = ""
                    if ($('.uploadbox .inHidden')) {
                        for (var i = 0; i < $('.uploadbox .inHidden').length; i++) {
//                        attachmentId+=$('.uploadbox .inHidden').eq(i).val()+','
                            attachmentId += $('.uploadbox .inHidden').eq(i).val()
                            attachmentName += $('.uploadbox ').find('.dech>a').eq(i * aTagNumber).attr('NAME')
                        }
                    }
                    if (attachmentId != '') {
                        var attachmentIdArr = attachmentId.split('?')[1];
                        var attachmentName = attachmentName;
                        var attachmentUrl = attachmentIdArr;
                    }



                    var data = {
                        'budgetId': budgetId,
                        'budgetItemNo': $('#budgetItemNo').val(),
                        'quotaClassify': $('#quotaClassify').val(),
                        'budgetItemName': $('#budgetItemName').val(),
                        'budgetItemBegindate': $('#budgetItemBegindate').val(),
                        'budgetItemEnddate': $('#budgetItemEnddate').val(),
                        'inputTime': $('#inputTime').val(),
                        'deptId': $('#department').attr('deptId').replace(',', '') || "",
                        "remainingAmount": Number($('#remainingAmount').val())+Number($('#allAdvance').val()),
                        'lineNo': $('#lineNo1').val(),

                        'itemMoney': $('#zhuiMon').val(),
                        /* 'itemRate':$('#itemRate').val(),*/
                        'itemExecuter': $('#itemExecuter').attr('user_id'),
                        'itemManager': $('#itemManager').attr('user_id'),
                        'itemDesc': $('#itemDesc').val(),
                        'priveItem': $('#priveItem option:checked').text(),
                        'attachmentName': attachmentName,
                        'attachmentId': attachmentId
                    }

                    $.ajax({
                        url: '/budget/upBudgetItemById',
                        type: 'post',
                        data: data,
                        dataType: 'json',
                        success: function (res) {
                            if (res) {
                                layer.msg("编辑成功", {
                                    icon: 1,
                                    time: 1500 //2秒关闭（如果不配置，默认是3秒）
                                }, function () {
                                    location.href = "/budget/budgetItemManage"
//                                window.location.reload()
                                });
                            }
                        }
                    })
                })

            }

            function mustWrite() {
                if ($('#budgetItemNo').val() == "") {
                    $.layerMsg({content: '请填写项目排序号！', icon: 2});
                    return false;
                }
//            if ($('#quotaClassify').val() == "") {
//                $.layerMsg({content: '指标分类！', icon: 2});
//                return false;
//            }
                if ($('#budgetItemName').val() == "") {
                    $.layerMsg({content: '请填写项目名称！', icon: 2});
                    return false;
                }
                if ($('#budgetItemBegindate').val() == "") {
                    $.layerMsg({content: '请填写开始时间！', icon: 2});
                    return false;
                }
                if ($('#budgetItemEnddate').val() == "") {
                    $.layerMsg({content: '请填写结束时间！', icon: 2});
                    return false;
                }
//            if ($('#inputTime').val() == "") {
//                $.layerMsg({content: '请填写录入时间！', icon: 2});
//                return false;
//            }
                if ($('#department').val() == "") {
                    $.layerMsg({content: '请选择所属部门！', icon: 2});
                    return false;
                }

                // if ($('#lineNo2').val() == "") {
                //     if($('#lineNo3').val() == ''){
                //         $.layerMsg({content: '请填写额度号！', icon: 2});
                //         return false;
                //     }
                // }

                /*if ($('#priveItem').val() == "") {
                    $.layerMsg({content: '请选择上级项目！', icon: 2});
                    return false;
                }*/
                if ($('#itemMoney').val() == "") {
                    $.layerMsg({content: '请填写项目金额！', icon: 2});
                    return false;
                }
                /*if ($('#itemRate ').val() == "") {
                    $.layerMsg({content: '请填写项目执行进度！', icon: 2});
                    return false;
                }*/
                if ($('#itemManager').val() == "") {
                    $.layerMsg({content: '请选择项目负责人！', icon: 2});
                    return false;
                }
                if ($('#itemExecuter').val() == "") {
                    $.layerMsg({content: '请选择项目执行人！', icon: 2});
                    return false;
                }

//            if ($('#itemDesc').val() == "") {
//                $.layerMsg({content: '项目描述！', icon: 2});
//                return false;
//            }

            }


            if (type == 3) {
                var itemDesc = $('#itemDesc').val();
                $('input').attr('disabled', true);
                $('input').attr('placeholder', '');
                $('#itemDesc').attr('disabled', true);
                $('.nav').text('填报明细');
                $('.btn').remove();
                $('.last').text('附件信息：');
                $('#uploadimgform').remove();
                $('#save').remove();

                $.ajax({
                    url: '/budget/selBudgetItemById',
                    type: 'get',
                    data: {
                        'budgetId': budgetId
                    },
                    dataType: 'json',
                    success: function (res) {
                        var obj = res.object
                        if (res) {
                            inputcheck('budgetItemNo', obj.budgetItemNo);
                            inputcheck('quotaClassify', obj.quotaClassify);
                            inputcheck('budgetItemName', obj.budgetItemName);
                            inputcheck('budgetItemBegindate', obj.budgetItemBegindate);
                            inputcheck('budgetItemEnddate', obj.budgetItemEnddate);
                            inputcheck('inputTime', obj.inputTime);
                            inputcheck('department', obj.department);
                            inputcheck('lineNo', obj.lineNo);
                            preveCheck('priveItem>option:selected', obj.priveItem);
                            inputcheck('itemMoney', obj.itemMoney);
                            /* inputcheck('itemRate',obj.itemRate);*/
                            inputcheck('itemManager', obj.itemManager);
                            inputcheck('itemExecuter', obj.itemExecuter);
                            inputcheck('itemDesc', obj.itemDesc);
                        }
                    }
                })
            }
            $('.back').click(function () {
                location.href = "/budget/budgetItemManage"
            })
            // $('#priveItem').change(function(){
            //
            //     if($('#priveItem option:checked').text()=='无'){priveItem
            //
            //         $('#lineNo1').hide()
            //     }

            // if($('#priveItem option:checked').text()!='请选择上级项目' && $('#priveItem option:checked').text()!='无') {
            //     // $('#lineNo1').show()
            //     $('#lineNo2').val('')
            //     // $('#lineNo1').val('')ConditionsInput
            //     $.ajax({
            //         url: '/budget/selOneLineNo',
            //         type: 'get',
            //         data: {
            //             'budgetItemName': $('#priveItem option:checked').text()
            //         },
            //         dataType: 'json',
            //         success: function (res) {
            //             var ss = res.split(',')[0]
            //             if (res) {.
            //                 inputcheck('lineNo1', ss);
            //             }
            //         }
            //     })
            // }else{
            //     inputcheck('lineNo1', '');
            // }

            // })
            $('#uploadinputimg').fileupload({
                dataType: 'json',
                done: function (e, data) {
                    if (data.result.obj != '') {
                        var data = data.result.obj;
                        var str = '';
                        var str1 = '';
                        for (var i = 0; i < data.length; i++) {
                            var gs = data[i].attachName.split('.')[1];
                            if (gs == 'jsp' || gs == 'css' || gs == 'js' || gs == 'html' || gs == 'java' || gs == 'php') {
                                str += '';
                                layer.alert('jsp、css、js、html、java文件禁止上传!', {}, function () {
                                    layer.closeAll();
                                });
                            } else {
                                str += '<div class="dech" attachmentId="' + data[i].aid + '@' + data[i].ym + '_' + data[i].attachId + '," attachmentUrl="' + encodeURI(data[i].attUrl) + '" style="display:block;margin:6px 0;"><a class="ATTACH_a" NAME="' + data[i].attachName + '*" href="<%=basePath %>download?' + encodeURI(data[i].attUrl) + '"><img src="/img/attachment_icon.png" style="margin-right:5px" alt="">' + data[i].attachName + '</a><img class="deImgs" style="margin-left:5px;cursor: pointer;" src="../img/file/icon_deletecha_03.png"/><input type="hidden" attachmentName="' + data[i].attachName + '*"  class="inHidden" value="' + data[i].aid + '@' + data[i].ym + '_' + data[i].attachId + ',"></div>';
                            }
                        }
                        $('.uploadbox').append(str);
                    } else {
                        //alert('添加附件大小不能为空!');
                        layer.alert('添加附件大小不能为空!', {}, function () {
                            layer.closeAll();
                        });
                    }
                }
            });
        })

</script>
</html>
